package com.itheima.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class ServerDemo {

    public static void main(String[] args) throws Exception {
        //创建 接收端对象  必须指定端口号
        DatagramSocket ds = new DatagramSocket(8888);
        //创建接受数据的对象
        byte[] bytes = new byte[1024*64];
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length);
        //接受   阻塞
        ds.receive(dp);
        //组织数据
        //ds
        //byte[] data = dp.getData();
        int length = dp.getLength();
        String s = new String(bytes,0, length);
        System.out.println(s);
        //释放资源
        ds.close();

    }
}
